import { isAuth} from "@/services/user";
import {history} from 'umi';

export function onRouteChange({ location }) {
  const {pathname} = location;
  if (pathname === '/user/login' || pathname === '404')
    return;
  // 权限验证
  isAuth({route: pathname}).then((res) => {
    const code = res?.data;
    if (code === '401') {
      // console.log('onRouteChange: 401 location=', pathname);
      history.push('/user/login');
    }else if (code === '403') {
      // console.log('onRouteChange: 403 location=', pathname);
      history.push('404');
    }
  });
}